package com.zelin.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zelin.shop.dao.ItemCatDao;
import com.zelin.shop.entity.ItemCatEntity;
import com.zelin.shop.service.ItemCatService;
import com.zyg.common.utils.PageUtils;
import com.zyg.common.utils.Query;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("itemCatService")
public class ItemCatServiceImpl extends ServiceImpl<ItemCatDao, ItemCatEntity> implements ItemCatService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ItemCatEntity> page = this.page(
                new Query<ItemCatEntity>().getPage(params),
                new QueryWrapper<ItemCatEntity>()
        );

        return new PageUtils(page);
    }

    //1. 查询一级分类
    @Override
    public List<ItemCatEntity> findItemCat1() {
        List<ItemCatEntity> itemCatEntities = baseMapper.selectList(new QueryWrapper<ItemCatEntity>().eq("parent_id", "0"));
        return itemCatEntities;
    }

    //2. 根据父id得到其下子分类列表
    @Override
    public List<ItemCatEntity> findParentById(Long newId) {
        return baseMapper.selectList(new QueryWrapper<ItemCatEntity>().eq("parent_id",newId));
    }

}